#pragma once
#include <windows.h>

#include "Physics\Dynamics\Entity\hkpRigidBody.h"
#include "Physics\Collide\Shape\hkpShape.h"

#include "..\common\def.h"
#include "..\common\string.h"
#include "..\common\arraylist.hpp"
#include "..\engine\object.h"
#include "..\render\d3d_mesh.h"
#include "..\math\matrix.h"

class EE_EXPORT CActor
{
	friend class CPhysics;
protected:
	hkpRigidBody* m_pActor;
	ArrayList<hkpCollisionListener*> m_CollisionListeners;

	CPhysics* m_pPhysics;
	
	Matrix4f m_Transform;
	Vector3f m_Velocity;
	bool m_AllowSetStill;
	
	void Simulate();
	CActor(CPhysics* const pPhysics);

	HRESULT CreateShape(const string &filename, hkpShape** pOut);

public:
	struct EE_EXPORT ActorData
	{
		Matrix4f initalTransform;
		float mass;
		float restitution;
		float friction;
		float linearDampening;
		float angularDampening;

		float maxLinearSpeed;
		float maxForce;
		float maxSlope;
		float maxAngularSpeed;

		ActorData();
	};
	~CActor();

	enum ResponceType 
	{
		UNAFFECTED = 0,
		NORMAL = 1
	};

	virtual HRESULT Create(const string &filename, CActor::ActorData actorData = CActor::ActorData(), CObject* pParent = NULL);
	
	HRESULT Release();

	void SetTransform(const Matrix4f& transform);
	void SetResponceToObject(CObject* pObject, const ResponceType& type);
	virtual void SetCollisionCallback(CObject* pObject);
	void SetAngluarVelocity(const Vector3f& axisMagnitude);
	void SetLinearVelocity(const Vector3f& directionMagnitude);
	void AddForce(const Vector3f& force);

	void SetLinearDamping(const float value);

	Matrix4f GetTransform() const;
	Vector3f GetLinearVelocity() const;
	void SetStill(bool val);
	
	

};
